#ifndef ISSET_H
#define ISSET_H

#include <memory.h>

template <class T>
class SSet
{
public:
	SSet(int nnum);
	~SSet();
	void Clear();
	bool AddSet(T*nset,int num);
	int GetNum(){return num;}
	int GetNum(int l){return s_num[l];}



	void Start();
	void NextI();
	void NextJ();
	T*GetCurrent();
	int I(){return i;}
	int J(){return i;}
	bool DoneI();
	bool DoneJ();

	T**el;

private:

	int*s_num;
	int num;
	int max_num;


	int i,j;

};


template <class T>
SSet<T>::SSet(int nnum):num(0),max_num(nnum)
{
	el = new T*[nnum];
	s_num=new int[nnum];
}

template <class T>
SSet<T>::~SSet()
{
	Clear();
	delete[]el;
	delete[]s_num;
}

template <class T>
void SSet<T>::Clear()
{
	for(int i=0;i<num;i++)
		delete[]el[i];
	num=0;
	
}

template <class T>
bool SSet<T>::AddSet(T*nset,int nnum)
{
	if(num==max_num)return false;

	el[num] = new T[nnum];
	s_num[num]=nnum;

//	T*ce = el[num];
//	for(int i=0;i<nnum;i++,ce++,nset++)
//		*ce = *nset;
	memcpy(el[num],nset,sizeof(T)*nnum);

	num++;
	return true;
}


template <class T>
void SSet<T>::Start()
{
	i=0;j=0;
}

template <class T>
void SSet<T>::NextJ()
{
	j++;
}

template <class T>
void SSet<T>::NextI()
{
	i++;
	j=0;
}

template <class T>
bool SSet<T>::DoneJ()
{
	return (j>=s_num[i]);
}

template <class T>
bool SSet<T>::DoneI()
{
	return (i>=num);
}

template <class T>
T* SSet<T>::GetCurrent()
{
	return el[i]+j;
}



#endif